<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var obj = {
            name: "huohua",
            age: 18,
            obj: {
                grade: 60

            },
            say() {
                console.log("这是一个方法");
            }
        }
        // 函数(方法)不可以拷贝
        // var obj02 = (JSON.parse(JSON.stringify(obj)))
        // console.log(obj02);


        function fn(obj) {
            var newObj = null
            if (typeof (obj) === 'object' && obj != null) {
                return newObj = obj
            } else {
                for (var item in obj) {
                    if (typeof obj[item] == "object") {
                        newObj[item] = fn(obj[item])
                    } else {
                        newObj[item] = obj[item]
                    }
                }
            }
            return newObj
        }
        var obj03 = fn(obj)
        console.log(obj03);
    </script>
</body>

</html>